#########################################################################
#
# Copyright 2008 Gavin Bong 
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may 
# not use this file except in compliance with the License. You may obtain 
# a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 
# implied. See the License for the specific language governing 
# permissions and limitations under the License. 
#
#########################################################################

import random
from soaplib_handler import DjangoSoapApp, soapmethod, soap_types, wrapper 

class Returning(wrapper.ClassSerializer):
    soap_members = {}
    namespace = 'http://www.jajah.com/' 

    def __init__(self):
       wrapper.ClassSerializer.__init__(self)

    GetRateResult = 1
    rate = 1.20
    isFree = False 
    currencyId = 1
    freeMinutesLeft = "10000"

class WebService(DjangoSoapApp):

    __tns__ = 'http://www.jajah.com/'

    @soapmethod(soap_types.String, soap_types.String, soap_types.String, soap_types.Array(soap_types.String), soap_types.Integer, _returns=Returning)
    def GetRate(self,userName,password,source,destinations,serviceType):
         results = Returning()

         results.soap_members['GetRateResult'] = soap_types.Integer
         results.soap_members['rate'] = soap_types.Float
         results.soap_members['isFree'] = soap_types.Boolean
         results.soap_members['currencyId'] = soap_types.Integer
         results.soap_members['freeMinutesLeft'] = soap_types.String

         r = random.randrange(-11,20,1)

         if r == 0:
             results.GetRateResult = r + 1;
         else:
             results.GetRateResult = r

         if r >= 1:
             results.rate = random.uniform( 1,5 )
         else:
             results.rate = 0

         results.isFree = False;
         results.currencyId = 1;
         results.freeMinutesLeft = "100"

         return results


getrate_service = WebService()
